#include <iostream>
#define M 100
using namespace std;

//邻接矩阵存储结构
struct AMGraph {
    char vexs[M];
    int arcs[M][M] = {0};
    int vexnum, arcnum;
};

//初始化空的图G
void InitGraph(AMGraph &G)
{
    G.vexnum = G.arcnum = 0;
}

//在图G中增加顶点v，返回顶点编号
int AddVertex(AMGraph &G, char v)
{
    if(G.vexnum >= M)
        throw "Graph is full";
    G.vexs[G.vexnum++] = v;
    return G.vexnum - 1;
}

//在图G中增加边v1-v2，其权值weight
void AddEdge(AMGraph &G, int v1, int v2, int weight = 1)
{
    if(v1 < 0 || v1 >= G.vexnum || v2 < 0 || v2 >= G.vexnum)
        throw "Vertex not found";
    G.arcs[v1][v2] = G.arcs[v2][v1] = weight;
    G.arcnum++;
}

//在图G中增加弧v1-v2，其权值weight
void AddArc(AMGraph &G, int v1, int v2, int weight = 1)
{
    if(v1 < 0 || v1 >= G.vexnum || v2 < 0 || v2 >= G.vexnum)
        throw "Vertex npt found";
    G.arcs[v1][v2] = weight;
    G.arcnum++;
}

int main()
{
    //创建图的邻接矩阵
    AMGraph G;
    InitGraph(G);
    int a = AddVertex(G, 'A');
    int b = AddVertex(G, 'B');
    int c = AddVertex(G, 'C');
    int d = AddVertex(G, 'D');
    AddEdge(G, a, b);
    AddEdge(G, a, c);
    AddEdge(G, a, d);
    AddEdge(G, b, c);
    AddEdge(G, c, d);

    //打印顶点
    for(int i = 0; i < G.vexnum; i++) {
        if(i > 0) cout << " ";
        cout << G.vexs[i];
    }
    cout << endl;

    //打印邻接矩阵
    for(int i = 0; i < G.vexnum; i++) {
        for(int j = 0; j < G.vexnum; j++) {
            if(j > 0) cout << " ";
            cout << G.arcs[i][j];
        }
        cout << endl;
    }
    return 0;

    return 0;
}